package org.usmile.algorithms.huawei.acm;

import java.util.Arrays;
import java.util.Scanner;

// https://blog.csdn.net/qq_34465338/article/details/128609355
public class _云短信平台优惠活动 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = Integer.parseInt(sc.nextLine());
        Integer[] p =
                Arrays.stream(sc.nextLine().split(" ")).map(Integer::parseInt).toArray(Integer[]::new);

        System.out.println(getResult(m, p));
    }

    public static int getResult(int capacity, Integer[] p) {
        int[] dp = new int[capacity + 1];
        for (int i = 1; i <= p.length; i++) {
            for (int j = i; j <= capacity; j++) {
                dp[j] = Math.max(dp[j], dp[j - i] + p[i - 1]);
            }
        }

        return dp[capacity];
    }
}
